setwd("~/Dropbox/Historical Displacement and Ethnicity - Afghanistan/REPOSITORY/")

library(haven)
library(dplyr)
library(FactoMineR)
library(factoextra)

# Read the data
data <- read_dta("replication/data/input/FOGHORN.dta")

# Prepare data for PCA, rename income_pc for the plot
pca_data <- data %>%
  select(income_pc, hunger, possess) %>%
  na.omit() %>%
  rename(`income per capita` = income_pc)

# Run PCA
res.pca <- PCA(pca_data, scale.unit = TRUE, graph = FALSE)

# Export to PDF and create the factor map plot
pdf("replication/results/figures/FigureA3.pdf")
fviz_pca_var(res.pca,
             col.var = "black",
             repel = TRUE,
             title = "Variables factor map (PCA)")
dev.off()
